package com.efuture.servlet.serveletcontext;

import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import java.io.IOException;

/**
 * @description: 通过ServletContext获取MimeType
 * @author zhaoshanshan
 * @date 2021/10/3 2:52 下午
 * @version 1.0
 */
@WebServlet("/GetMimeType")
public class GetMimeType extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        doPost(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

        ServletContext servletContext = this.getServletContext();
        String fileName = "a.jpg";
        String mimeType = servletContext.getMimeType(fileName);
        System.out.println(mimeType);//image/jpeg


    }
}
